package com.sky.controller.user;

import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.NoticeService;
import com.sky.vo.NoticeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userNoticeController")
@RequestMapping("/user/notice")
@Api(tags = "C端-公告相关接口")
@Slf4j
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @GetMapping("/latest")
    @ApiOperation("获取最新公告")
    public Result<NoticeVO> getLatestNotice() {
        NoticeVO noticeVO = noticeService.getLatestNotice();
        return Result.success(noticeVO);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询公告")
    public Result<PageResult> pageQuery(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult pageResult = noticeService.pageQueryForUser(page, pageSize);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询公告详情")
    public Result<NoticeVO> getById(@PathVariable Long id) {
        NoticeVO noticeVO = noticeService.getByIdForUser(id);
        return Result.success(noticeVO);
    }
}